﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Linq.Expressions;
using System.Text;
using System.Threading.Tasks;
using Zhao.Common.Helper;
using Zhao.Models.AppletDto;
using Zhao.Models.DTO;
using Zhao.Models.Entity;

namespace Zhao.IServer.Events
{
    /// <summary>
    /// 活动主表
    ///</summary>
    public interface IActivitiesServer : IBaseService<Activities>
    {
        /// <summary>
        /// 查询活动详情
        /// </summary>
        /// <param name="expressionable"></param>
        /// <param name="pageIndex"></param>
        /// <param name="pageSize"></param>
        /// <returns></returns>
        public Task<PageModel<ActivitiesDTO>> ActivitiQueryPageModel(Expression<Func<Activities, Venues, FieldTypes, bool>> expressionable, int pageIndex, int pageSize);

        /// <summary>
        /// 取消活动并退款给所有报名用户
        /// </summary>
        /// <param name="activityId">活动ID</param>
        /// <param name="operatorId">操作人ID</param>
        /// <param name="cancelReason">取消原因</param>
        /// <returns>取消结果</returns>
        Task<ApiResult> CancelActivityAsync(int activityId, int operatorId, string cancelReason);

        #region 定时任务    
        /// <summary>
        /// 更新今日活动状态
        /// </summary>
        /// <returns>更新的记录数</returns>
        public Task<int> UpdateActivitiesStatusAsync();

        /// <summary>
        /// 更新历史活动状态
        /// </summary>
        /// <returns>更新的记录数</returns>
        Task<int> UpdateHistoricalActivitiesStatusAsync();

        /// <summary>
        /// 结算AA制活动，对用户进行多退少补，并将费用结算给商户
        /// </summary>
        /// <param name="settlementDto">结算信息</param>
        /// <param name="venueId">球馆ID</param>
        /// <param name="operatorId">操作人ID</param>
        /// <returns>结算结果</returns>
        Task<ApiResult> SettleAAActivityAsync(AAActivitySettlementDto settlementDto, Guid venueId, int operatorId);
        #endregion

        #region 小程序端API

        /// <summary>
        /// 小程序端创建活动
        /// </summary>
        /// <param name="dto">活动信息</param>
        /// <param name="venueId">球馆ID</param>
        /// <param name="userId">用户ID</param>
        /// <returns>创建结果</returns>
        Task<ApiResult> CreateActivityAsync(ActivityCreateDto dto, Guid venueId, int userId);

        /// <summary>
        /// 获取活动类型列表
        /// </summary>
        /// <returns>活动类型列表</returns>
        Task<List<FieldTypeOption>> GetFieldTypesAsync();

        /// <summary>
        /// 活动报名
        /// </summary>
        /// <param name="dto">报名信息</param>
        /// <returns>是否报名成功</returns>
        Task<bool> ApplyActivityAsync(ApplyDto dto);

        /// <summary>
        /// 获取活动数据分页
        /// </summary>
        /// <param name="expressionable"></param>
        /// <param name="pageIndex"></param>
        /// <param name="pageSize"></param>
        /// <returns></returns>
        public Task<PageModel<AppActivitiesDto>> AppletActiviQueryAsync(Expression<Func<Activities, Venues, FieldTypes, bool>> expressionable, int pageIndex, int pageSize);

        /// <summary>
        /// 根据活动id获取对应的活动详情数据
        /// </summary>
        /// <param name="keyId"></param>
        /// <param name="userId"></param>
        /// <returns></returns>
        public Task<ActivitiesDetailedDto> AppleActiviGetById(int keyId, int userId);

        /// <summary>
        /// 修改报名信息（增加/减少人数，扣款/退款，更新订单）
        /// </summary>
        /// <param name="dto">报名信息</param>
        /// <returns>修改结果</returns>
        Task<ApiResult> UpdateApplyInfoAsync(ApplyDto dto, int oldNumber, Users user);

        /// <summary>
        /// 取消报名
        /// </summary>
        /// <param name="dto">取消报名信息</param>
        /// <param name="refundAmount">退款金额</param>
        /// <param name="member">报名信息</param>
        /// <param name="oldOrder">原订单</param>
        /// <param name="user">用户信息</param>
        /// <returns>取消结果</returns>
        Task<ApiResult> CancelApplyAsync(CancelApplyDto dto, ActivityMembers member, Orders oldOrder, Users user);

        /// <summary>
        /// 获取用户参与的活动列表
        /// </summary>
        /// <param name="userId">用户ID</param>
        /// <returns>用户活动列表</returns>
        Task<UserActivityListDto> GetUserActivitiesAsync(int userId);



        #endregion
    }
}
